<?php
namespace app\api\model;
use think\Model;
//订单模型
class Order extends Model{
    protected $autoWriteTimestamp = false;
    public function add($data){
        try {
           $orderId=$this->save($data);
           if($orderId){
               return $orderId;
           }else{
               return 0;
           }
        }catch (\think\Exception $e){
            trace('create exception'.$e->getMessage());
        }
    }
    //订单号查询
    //场馆的订单号查询
    public function selectOrder($place_id){
        $where=array('place_id'=>$place_id);
       $res=$this->where($where)->select();
       if(empty($res)){
           return 0;
       }else{
           return $res;
       }
    }
    //用户查询自己的订单
    public function selectOrderByUser($user_id){
        $res=$this->where(array('user_id'=>$user_id))->select();
        if(!empty($res)){
            return $res;
        }else{
            return 0;
        }
    }
    //删除订单
    public function deleteAll($user_id){
       $id=$this->destroy($user_id);
       if($id){
           return 1;
       }else{
           return 0;
       }
    }
    /**
     * 
     * @param int $user_id 用户ID
     * @param int $orderId 订单Id
     */
    public function editStaus($user_id,$orderId,$status=0){
        try {
           $res=$this->where(array('user_id'=>$user_id,'orderId'=>$orderId))->setField('status',$status);
           if($res){
               return 1;
           }else{
               return 0;
           }
        }catch (\think\Exception $e){
            die($e->getMessage());
        }
    }
}